<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>

  <style> 

    .box {
      width: 100px;
      height: 100px;
      background-color: red;
    }
  </style>
</head>
<body>

  <div class="box"></div>

  <script>

    function debounce(fn, delay) {
      let timer = null;
      return function (...args) {
        if (timer) {
          clearTimeout(timer);
        }
        timer = setTimeout(() => {
          fn.apply(this, args);
        }, delay);
      };

    }

    const debounceClick = debounce(() => {
      console.log('333')
    }, 1000, {
      leading: true,
      trailing: false,
      // maxWait: 3000
    })

    document.querySelector('.box').onclick = () => {
      debounceClick()
    }

    
  </script>
</body>
</html>